<?php
class indexControl extends Control{
    
 public	function index(){
		$db=M('news');
		$aiqing=$db->where("catid=1")->limit(6)->order("id asc")->all();
		$youqing=$db->where("catid=2")->limit(6)->order("id asc")->all();
		$qinqing=$db->where("catid=3")->limit(6)->order("id asc")->all();
		$aq=$this->str($aiqing);
		$this->assign("aiqing",$aq);
		$this->display();
	}
	
//函数处理字符串的 
	public function str($aiqing){
		foreach($aiqing as $key=>$value){
				$title = $aiqing[$key]["title"];
				if(strlen($title)>48){
					$title = substr($aiqing[$key]["title"], 0,42)."......";
				}else{
					$title = $aiqing[$key]["title"];
				}
				$aiqing[$key]["title"] = $title;
				$aiqing[$key]["addtime"] = date("Y-m-d",$aiqing[$key]["addtime"]);
			}
	
	       	return $aiqing;
	
		}

	public function login(){
		//C("debug",0);
		$sess=$_SESSION['code'];
		$co_post=$_POST['code'];
		if(!$sess==$co_post){
		   $this->error('验证码错误');
		}
		if(empty($_POST["username"])){
			$this->error("用户名不能为空");
		}else{
			$name=$_POST['username'];
			$pwd=$_POST['password'];
			$db=M('user');
			$userInfo=$db->where("username='".$name."'")->find();
			if(empty($userInfo["uid"])){
				$this->error("用户名不存在！");		
			}else{
				if($userInfo["password"]!=md5($_POST["password"])){
					$this->error("密码错误！");
				}else{
					$_SESSION["user"] = $userInfo;
					
					$this->go("index");
				}
			}
		}
		

	}


    public function out(){
      session_destroy();
       $this->success('您已成功退出');


}







}

